<?php
/**
 * Created by PhpStorm.
 * User: 丶晓
 * Date: 2017/8/24
 * Time: 16:59
 */

namespace app\api\common;


use app\common\Base;

class Tools extends Base
{
    public static function success($msg, $data = null) // 正确返回格式
    {
        if (empty($data)) {
            return json_encode(['state' => true, 'msg' => $msg], JSON_UNESCAPED_UNICODE);
        }
        return json_encode(['state' => true, 'data' => $data], JSON_UNESCAPED_UNICODE);
    }

    public static function error($msg, $data = null) // 错误返回格式
    {
        if (empty($data)) {
            return json_encode(['state' => false, 'msg' => $msg], JSON_UNESCAPED_UNICODE);
        }
        return json_encode(['state' => false, 'data' => $data], JSON_UNESCAPED_UNICODE);
    }

    public static function getOnlyMd5($key = null) // 获取新增唯一ID值
    {
        return $key ? strtoupper(md5($key)) : strtoupper(md5(uniqid()));
    }

}